<?php

	
	// get the oauth_token and the oauth_token_secret and save it with the phone number
	if(!empty($_GET['oauth_token'])) {

			// Create TwitterOAuth object with app key/secret
			$to = $cfg->getTwitter($_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
			
			// Request tokens from twitter
			$tok = $to->getAccessToken();

			$user->tw_token = $tok['oauth_token'];
			$user->tw_secret = $tok['oauth_token_secret'];
			$user->save();

			$request_link = "#";

	} else {
		
	    // Create TwitterOAuth object with app key/secret
	    $to = $cfg->getTwitter();

	    // Request tokens from twitter
	    $tok = $to->getRequestToken();

	    $_SESSION['oauth_request_token'] = $tok['oauth_token'];
	    $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];

	    // Build the authorization URL
	    $request_link = $to->getAuthorizeURL($_SESSION['oauth_request_token']);

	}

	$Smarty->assign('request_link', $request_link);
	$Smarty->assign('page', 'publish.tpl');


?>
